﻿using PictureInterference.Helper;
using PictureInterference.Helper.Currency;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PictureInterference
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            InitView();
        }

        private void InitView()
        {
            FloderHelper.FloderExits(StaticValue.FontTempPath1,true);
            comboBox1.Items.AddRange(FileHelper.GetFullFileNameList(StaticValue.FontTempPath1).ToArray());
            comboBox2.SelectedIndex = 1;
            comboBox1.SelectedIndex = 0;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = Helper.CreateText.InterferenceHelper.CreateText(GetCount(),richTextBox1.Text);
            InitRichBox();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FloderHelper.OpenFloder(".\\");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            PrivateFontCollection GetFont = FontHelper.ReadFontFile(Application.StartupPath+ comboBox1.Text.Substring(1));
            Console.WriteLine(Application.StartupPath + comboBox1.Text.Substring(1));
            FontFamily myFontFamily = new FontFamily(GetFont.Families[0].Name, GetFont);
            Font myFont = new Font(myFontFamily, 14F, FontStyle.Strikeout);
            //设置字体            
            richTextBox1.Font = myFont;
            
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            Console.WriteLine("文字改变"+richTextBox1.Text);
            ChangedText();
        }
        
        private void ChangedText()
        {
            string Temptext = richTextBox1.Text + Helper.CreateText.InterferenceHelper.CreateInterfere(GetCount());
            if (DeleteFlag)
                richTextBox1.Text = Temptext;
            InitRichBox();
        }

        private void InitRichBox()
        {
            richTextBox1.Focus();
            richTextBox1.Select(richTextBox1.Text.Length, 0);
        }

        /// <summary>
        /// 获取干扰次数
        /// </summary>
        /// <returns></returns>
        private int GetCount()
        {
            switch (comboBox2.Text)
            {
                case "不干扰":

                case "":
                    break;
                case "弱干扰":
                    return 1;
                    
                case "强干扰":
                    return 2;
                   
                case "超强干扰":
                    return 3;
            }
            return 3;
        }

        bool DeleteFlag = true;
        private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Enter)
            {
                DeleteFlag = false;
                return;
            }

            DeleteFlag = true;
        }
    }
}
